home *** CD-ROM | disk | FTP | other *** search
- /* -*- Mode: Elec-C -*-
- * size68.c -- report segment sizes take from program header
- *
- * Author : probably J.R.Bammi
- * Created On : some years ago
- * Last Modified By: Frank Ridderbusch
- * Last Modified On: Wed Apr 14 21:22:02 1993
- * Update Count : 6
- * Status : Unknown, Use with caution!
- */
-
- /* HISTORY
- * 14-Apr-1993 Frank Ridderbusch
- * Deleted the prgflags structure in this file, since it is in
- * <st-out.h>. Added code to report status on all prgflags defined
- * upto now.
- */
-
- #include <stdio.h>
- #ifdef CROSSATARI
- #include "cross-inc/st-out.h"
- #else
- #include <st-out.h>
- #endif
-
- /*
- * ldflgs - stolen from MiNT mem.h
- */
-
- #define F_PROTMODE 0xf0 /* protection mode bits */
- #define F_PROT_P 0x00 /* no read or write */
- #define F_PROT_G 0x10 /* any access OK */
- #define F_PROT_S 0x20 /* any super access OK */
- #define F_PROT_PR 0x30 /* any read OK, no write */
-
- extern FILE *fopen();
-
- extern void dump_version(char *prog);
- char *progname = "size68";
-
- main(argc, argv)
- int argc;
- char **argv;
- {
- if (argv[0][0] != '\0')
- progname = argv[0];
-
- if (argc == 2 && strcmp(argv[1], "-v") == 0)
- {
- dump_version(progname);
- exit(0);
- }
-
- while(--argc > 0)
- showfile(*++argv);
- return 0;
- }
-
- showfile(name)
- char *name;
- {
- register FILE *fp;
- struct aexec h;
-
- if((fp = fopen(name, "rb")) == (FILE *)NULL)
- {
- perror(name);
- exit(1);
- }
- # ifndef WORD_ALIGNED
- if(fread(&h, sizeof(struct aexec), 1, fp) != 1)
- {
- perror(name);
- exit(2);
- }
- #else
- aligned_read(&h, fp);
- #endif
- fclose(fp);
-
- if(h.a_magic != CMAGIC)
- {
- fprintf(stderr,"Bad Magic #: 0X%x\n", h.a_magic);
- exit(3);
- }
- printf("%s:\n\ttext size\t%ld\n\tdata size\t%ld\n\tbss size\t%ld\
- \n\tsymbol size\t%ld\n\tFile %s relocatable.\n\
- \t%s cleared on startup.\n", name, h.a_text,
- h.a_data, h.a_bss, h.a_syms,
- (h.a_isreloc == ISRELOCINFO) ? "is" : "is not",
- (h.a_AZero2 & F_FASTLOAD) ? "Only BSS" : "BSS and high mem");
- printf("\tFile is loaded into %s\n",
- (h.a_AZero2 & F_ALTLOAD) ? "alternate ram" : "ST ram");
- printf("\t and allocates memory from %s.\n",
- (h.a_AZero2 & F_ALTALLOC) ? "alternate ram" : "ST ram");
- printf("\tFile runs with `%s' memory protection (under MultiTOS).\n",
- (((h.a_AZero2 & F_PROTMODE) == F_PROT_PR) ? "readable" :
- (((h.a_AZero2 & F_PROTMODE) == F_PROT_S) ? "super" :
- (((h.a_AZero2 & F_PROTMODE) == F_PROT_G) ? "global" : "private"))));
- }
-
- # ifdef WORD_ALIGNED
- void ckfread(buf, siz, n, fp)
- char *buf;
- int siz, n;
- FILE *fp;
- {
- if(fread(buf, siz, n, fp) != n)
- {
- perror("reading");
- exit(3);
- }
- }
-
- aligned_read(h, fp)
- struct aexec *h;
- FILE *fp;
- {
- short i;
- long j;
-
- ckfread(&i, 2, 1, fp);
- h->a_magic = i;
- ckfread(&j, 4, 1, fp);
- h->a_text = j;
- ckfread(&j, 4, 1, fp);
- h->a_data = j;
- ckfread(&j, 4, 1, fp);
- h->a_bss = j;
- ckfread(&j, 4, 1, fp);
- h->a_syms = j;
- ckfread(&j, 4, 1, fp);
- h->a_AZero1 = j;
- ckfread(&j, 4, 1, fp);
- h->a_AZero2 = j;
- ckfread(&i, 2, 1, fp);
- h->a_isreloc = i;
- }
- #endif
-
- #ifdef CROSSHPUX
- char *xmalloc(n)
- unsigned n;
- {
- extern char *malloc();
- char *ret = malloc(n);
-
- if(!ret)
- {
- fprintf(stderr,"Out of memory!\n");
- exit(1);
- }
- return ret;
- }
- #endif
-